package com.hpeu_01.CarApp;


//汽车业务类
public class Business {
    //汽车类型的数组，将该数组声明为父类类型
    public Automobile[] auto = new Automobile[8];
    //初始化汽车信息
    public void autoArray(){
        auto[0] = new Car("京NY28588","宝马",800,"X6");
        auto[1] = new Car("京CNY3284","宝马",600,"550i");
        auto[2] = new Car("京NY37465","别克",300,"林荫大道");
        auto[3] = new Car("京NT96968","别克",600,"GL8");
        auto[4] = new Bus("京6566754","金杯",800,16);
        auto[5] = new Bus("京8696997","金龙",800,16);
        auto[6] = new Bus("京9696996","金杯",1500,34);
        auto[7] = new Bus("京8696998","金龙",1500,34);
    }
    //定义一个方法判断租车的信息
    public Automobile autoDecide(String brand,String model,int seatsNumber){
        Automobile auto1 =null;
        for(Automobile autos : auto){
            if (autos instanceof Car){
                Car car =(Car)autos;
                if(car.getBrand().equals(brand)&& car.getModel().equals(model)){
                    auto1=car;
                    break;
                }
            }else {
                Bus bus = (Bus)autos;
                if (bus.getBrand().equals(brand)&&bus.getSeatsNumber()==seatsNumber){
                    auto1=bus;
                    break;
                }
            }
        }
        return auto1;
    }
}
